GNU readline

GNU readline
Original author(s) Brian Fox
Developer(s) Chet Ramey
Initial release 1989; 22 years ago (1989)
Stable release 6.2  (February 14, 2011; 11 months ago (2011-02-14))[1] [±]
Written in C
Operating system Various
Type Library
License GNU General Public License
Website Official website

GNU readline is a software library that provides line-editing and history capabilities for interactive programs with a command-line interface, such as Bash. It is currently maintained by Chet Ramey as part of the GNU Project.

It allows users to move the text cursor, search the command history, control a kill ring (a more flexible version of a copy/paste clipboard) and use tab completion on a text terminal.

Readline key bindings are taken from the text editor Emacs, but can be customized. As a cross-platform library, readline allows applications on various systems to exhibit identical line-editing behavior.

Contents

Choice of the GPL as GNU Readline's license

GNU Readline is notable for being a free software library which is licensed under the GNU General Public License (GPL) instead of the GNU Lesser General Public License (LGPL). Free software libraries are often licensed under the LGPL, for example, the GNU C Library, GNU gettext and FLTK.

A developer of an application who chooses to link to an LGPL licensed library when building a new application is required to have the LGPL licensed library which it uses remain under the LGPL when distributing the combined resulting application. The part of the combined application excluding the LGPL licensed library can remain under the original license.[2] This is in contrast to a developer choosing to use a GPL licensed library to create a new application, in which case the entire combined resulting application is required to be licensed under the GPL when distributed, to comply with section 5 of the GPL.[3][4]

This type of reciprocal licensing scheme is generally known as copyleft (more precisely the GPL and the LGPL are examples of strong and weak copyleft licenses respectively), and has ramifications for readline's integration into free software applications whose licences don't have any copyleft provisions (these licenses are usually referred to as permissive licenses).

Licensing GNU Readline under a a strong copyleft license like the GPL means that, if a developer of an application chooses to link that application with the readline library, they are obligated to change the license of the resulting application to the GPL if they wish to distribute the resulting application.

Implications of GNU Readline's GPL license

An important example of an application changing its licensing to comply with the copyleft conditions of GNU Readline is CLISP, an implementation of Common Lisp. Originally released in 1987, it changed to the GPL license in 1992,[5] after an email exchange between one of CLISP's original author's, Bruno Haible, and Richard Stallman, in which Stallman argued[6] that the linking of readline in CLISP meant that Haible was required to re-license CLISP under the GPL if he wished to distribute the implementation of CLISP which used readline.[7]

Since its initial release, some developers of permissively licensed software who have wanted to use the GNU readline library in their applications have occasionally expressed their annoyance[8] with the licensing conditions of readline on development mailing lists. Other developers have responded by stating that this is a waste of time.[9]

Alternative command line editing libraries which are permissively licensed can be used by software projects which want to implement command line editing functionality, but wish to remain under a permissive license. For example the Glasgow Haskell Compiler uses Haskeline (which is licenced under the 3 clause BSD license). Similar libraries are listed in the external links.

Sample code

The following code is in C :

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
 
int main()
{
    char* input, shell_prompt[100];
 
    for(;;)
    {
        // getting the current user 'n path
        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
        // inputing...
        input = readline(shell_prompt);
        // eof
        if (!input)
            break;
	// path autocompletion when tabulation hit
        rl_bind_key('\t', rl_complete);
        // adding the previous input into history
        add_history(input);
 
        /*do stuff*/
    }
}

Notes and References

  1. ^ Ramey, Chet (2011-02-14). "Readline-6.2 available for FTP". info-gnu mailing list. http://lists.gnu.org/archive/html/info-gnu/2011-02/msg00013.html. Retrieved 2011-05-20. 
  2. ^ "GNU Lesser General Public License". The GNU Lesser General Public License v3.0 - GNU Project. Free Software Foundation. 2007. http://www.gnu.org/copyleft/lesser.html. Retrieved 2011-09-3. 
  3. ^ "GNU General Public License". The GNU General Public License v3.0 - GNU Project. Free Software Foundation. 2007. http://www.gnu.org/licenses/gpl-3.0.html. Retrieved 2011-09-3. 
  4. ^ "Frequently Asked Questions about the GNU licenses". Frequently Asked Questions about the GNU Licenses - GNU Project. Free Software Foundation. 2010. http://www.gnu.org/licenses/gpl-faq.html#IfLibraryIsGPL. Retrieved 2011-09-3. 
  5. ^ "CLISP copyright notice". CLISP repository. 1992. http://clisp.cvs.sourceforge.net/viewvc/clisp/clisp/COPYRIGHT. Retrieved 2011-09-3. 
  6. ^ "Why CLISP is under GPL". CLISP repository. 1992. http://clisp.cvs.sourceforge.net/viewvc/clisp/clisp/doc/Why-CLISP-is-under-GPL. Retrieved 2011-09-3. 
  7. ^ "License - why GNU GPL?". Frequently Asked Questions (With Answers) about CLISP. CLISP team. http://www.clisp.org/impnotes/faq.html#faq-gpl. Retrieved 2011-09-3. 
  8. ^ Momjian, Bruce (2001). "GPL, readline, and static/dynamic linking". PostgreSQL development mailing list. http://archives.postgresql.org/msgtxt.php?id=200102221550.KAA20883%40candle.pha.pa.us. Retrieved 2011-09-3. "This would seem to imply that our dynamic linking of libreadline in PostgreSQL backend binaries makes the distribution of backend binaries fall under the GPL. (Of course, we can use *BSD libedit now.) Let me add I don't agree with this, and find the whole GPL heavy-handedness very distasteful." 
  9. ^ Myers, Nathan (2001). "Re: GPL, readline, and static/dynamic linking". PostgreSQL development mailing list. http://archives.postgresql.org/msgtxt.php?id=20010222130327.A4314%40store.zembu.com. Retrieved 2011-09-3. "Please, not this again. Is there a piss-and-moan-about-the-GPL schedule posted somewhere? Either PG is in compliance, or it's not. Only libreadline's copyright holder has the right to complain if it's not. There is no need to speculate; if we care about compliance, we need only ask the owner. If the owner says we're violating his license, then we can comply, or negotiate, or stop using the code. The GPL is no different from any other license, that way. Complaining about the terms on something you got for nothing has to be the biggest waste of time and attention I've seen on this list." 

External links